import { login } from '@/api/system/login.api';
import { setToken } from '@/utils/auth';

const user = {
    state: {
        id: 0,
        access_token: '',
        account: '',
        avatar: '',
        user_name: ''
    },
    mutations: {

    },
    actions: {
        Login({commit}, data) {
            const username = data.username;
            const password = data.password;
            const userForm = {
                tenantId: '000000',
                username,
                password,
                grant_type: 'captcha',
                scope: 'all',
                type: 'accoumnt'
            }
            return new Promise((resolve,reject)=>{
                login(data.headers,userForm).then( res=> {
                    setToken(res);
                    resolve();
                }).catch(error => {
                    reject(error);
                })
            })
        }
    }
    
}
export default user